/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.schedule.manage.controller;


import info.peigen.hotpot.common.core.result.manage.WebResult;
import info.peigen.hotpot.component.data.repository.beetlsql.filter.ManageDataAspect;
import info.peigen.hotpot.component.schedule.facade.command.result.ScheduleNodeCreateResult;
import info.peigen.hotpot.component.schedule.facade.command.result.ScheduleNodeDeleteResult;
import info.peigen.hotpot.component.schedule.facade.command.result.ScheduleNodeEditResult;
import info.peigen.hotpot.component.schedule.manage.form.ScheduleNodeManageAddForm;
import info.peigen.hotpot.component.schedule.manage.form.ScheduleNodeManageDeleteForm;
import info.peigen.hotpot.component.schedule.manage.form.ScheduleNodeManageEditForm;
import info.peigen.hotpot.component.schedule.manage.form.ScheduleNodeManageSearchForm;
import info.peigen.hotpot.component.schedule.manage.service.ScheduleNodeManageService;
import jakarta.validation.Valid;
import org.noear.solon.annotation.Body;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;

/**
 * <b>(ScheduleNodeManageController)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2023/1/6
 */
@Controller
@Mapping("schedule/node")
public class ScheduleNodeManageController {
    @Inject
    private ScheduleNodeManageService scheduleNodeManageService;

    @Mapping
    @ManageDataAspect
    WebResult page(@Body ScheduleNodeManageSearchForm form) {
        return WebResult.setSuccessResult().setInfo(scheduleNodeManageService.page(form));
    }

    @Mapping("add")
    @ManageDataAspect
    WebResult add(@Valid @Body ScheduleNodeManageAddForm form) {
        ScheduleNodeCreateResult result = scheduleNodeManageService.add(form);
        if (result.success()) {
            return WebResult.setSuccessResult().setInfo(result.getInfo());
        }
        return WebResult.setFailure();
    }

    @Mapping("edit")
    @ManageDataAspect
    WebResult edit(@Valid @Body ScheduleNodeManageEditForm form) {
        ScheduleNodeEditResult result = scheduleNodeManageService.edit(form);
        if (result.success()) {
            return WebResult.setSuccessResult().setInfo(result.getInfo());
        }
        return WebResult.setFailure();
    }

    @Mapping("delete")
    WebResult delete(@Valid @Body ScheduleNodeManageDeleteForm form) {
        ScheduleNodeDeleteResult result = scheduleNodeManageService.delete(form);
        if (result.success()) {
            return WebResult.setSuccessResult().setInfo(result.getInfo());
        }
        return WebResult.setFailure();
    }

}